import com.zhouys.dao.BlogMapper;
import com.zhouys.pojo.Blog;
import com.zhouys.utils.IDutils;
import com.zhouys.utils.MybatisUtils;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

import java.util.Date;
import java.util.HashMap;
import java.util.List;

public class Mytest {


    @Test
    public   void  test(){
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        BlogMapper mapper = sqlSession.getMapper(BlogMapper.class);

        Blog blog = new Blog();
        blog.setId(IDutils.getID());
        blog.setTitle("Mybaits学习1");
        blog.setAuthor("zhouys");
        blog.setCreateTime(new Date());
        blog.setViews(666);
        mapper.addBook(blog);
//
        blog.setId(IDutils.getID());
        blog.setTitle("spring学习");
        mapper.addBook(blog);

        blog.setId(IDutils.getID());
        blog.setTitle("微服务学习");
        mapper.addBook(blog);

        sqlSession.close();
    }

    @Test
    public  void  query(){
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        BlogMapper mapper = sqlSession.getMapper(BlogMapper.class);
        HashMap blogs = new HashMap();
        blogs.put("title","微服务学习");
        blogs.put("author","zhouys");

        List<Blog> blogs1 = mapper.queryBlogIF(blogs);
        for (Blog blog : blogs1) {
            System.out.println(blog);
        }
        sqlSession.close();
    }



}
